package com.hmall.order.config;

import com.hmall.order.common.MQConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @Author Mingxi Guo
 * @Create 2022-07-18 8:53
 * @Email guomingxi2018@163.cm
 */

@Configuration
public class MQConfig {
    @Bean
    public CustomExchange delayExchange(){
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-delayed-type","direct");
        return new CustomExchange(MQConstants
                .DELAY_EXCHANGE,"x-delayed-message",true,false,args);
    }

    @Bean
    public Queue delayQueue(){
        return new Queue(MQConstants.DELAY_QUEUE);
    }

    @Bean
    public Binding bindingQueue(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(MQConstants.DELAY_ROUTING_KEY).noargs();
    }
}
